
package com.luxoft.sqedu.javalang;

public class ArrayList {
   // private Node head;
    private int size = 0;
    private Object[] element;
    private static final int volume = 20;

   /* class Node {
        Node next = null;
        int value = 0;
        Node prev = null;

        Node(int value) {
            this.value = volume;
        }
    }

    public void addToStart(int value) {
        Node newNode = new Node(value);

        if(head == null) {
            head = newNode;
        } else {
            newNode.next = head;
            newNode.prev = null;
            head = newNode;
        }
        size++;
    }
*/
    public ArrayList() {
        element = new Object[volume];
        size = 0;
    }

    public Object set(int index, Object obj) {
        Object result = element[index];
        element[index] = obj;
        return result;
    }

    public int size() {
        return size;
    }

    public boolean isEmpty() {
        return size() == 0;
    }

    public Object get(int index) {
        return element[index];
    }

    public void addFirst(Object element){
        if (size() == 0) { add(element);}
        else { add(0,element);}
    }

    public boolean add(Object obj) {
        element[size] = obj;
        size++;
        return true;
    }

    public boolean add(int index, Object obj) {

        for (int i = size(); i > index; i--) {
            element[i] = element[i-1];
        }
        element[index] = obj;
        size++;
        return true;
    }

    public Object remove(int index) {
        Object result = element[index];
        for (int i = index; i < size()-1; i++) {
            element[i] = element[i+1];
        }
        size--;
        element[size] = null;
        return result;
    }


    public boolean remove(Object obj) {
       return  true;
    }

   /* public void printArrayList() {
        ArrayList tmp = head;

        while(tmp.next != null) {
            tmp = tmp.next;
            System.out.println(tmp.value);
        }
    }*/
   public void printArrayList(Object obj)
   {
       System.out.println(String.valueOf(obj));
   }

}
